package swagger.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {
//配置swagger的docket的bean实例

    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("C");
    }

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .enable(false) // 关闭swagger
                .select()
                //RequestHandlerSelectors 配置扫描接口的方式
                //basePackage:指定扫描的包
                //any : 扫描全部
                //none: 不扫描
                //withClassAnnotation: 扫描类上的注解,参数是一个注解的反射对象
                //withmethodAnnotation: 扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("swagger.demo.controller"))
                //paths: 过滤路径
//                .paths(PathSelectors.ant("/swagger/**/"))
                .build(); //工厂模式
    }
    //配置swagger信息apiinfo
    Contact contact = new Contact("王凯", "https://www.ypyunedu.com/", "1262638533@qq.com");
    private ApiInfo apiInfo(){
        return new ApiInfo("大海的swaggerApi文档",
                "起飞",
                "1.0",
                "urn:tos",//url地址
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
